<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JSJaC Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="JSJaCPacket.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JSJaC</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>JSJaCPacket.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		Contains all Jabber/XMPP packet related classes.
 <BR/><BR/><B>Version: </B>$Revision: 437 $<BR/><BR/><B>Author:</B> Stefan Strigler steve@zeank.in-berlin.de
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCIQ.html">JSJaCIQ</a></b></td>
    <td>Models the XMPP notion of an 'iq' packet
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCMessage.html">JSJaCMessage</a></b></td>
    <td>Models the XMPP notion of an 'message' packet
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCPacket.html">JSJaCPacket</a></b></td>
    <td>Somewhat abstract base class for all kinds of specialised packets
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="JSJaCPresence.html">JSJaCPresence</a></b></td>
    <td>Models the XMPP notion of a 'presence' packet
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span> Contains all Jabber/XMPP packet related classes.
 * <span class="attrib">@author</span> Stefan Strigler steve<span class="attrib">@zeank</span>.in-berlin.de
 * <span class="attrib">@version</span> $Revision: 437 $
 */</span>

var JSJACPACKET_USE_XMLNS = true;

<span class="comment">/**
 * Creates a new packet with given root tag name (for internal use)
 * <span class="attrib">@class</span> Somewhat abstract base class for all kinds of specialised packets
 * <span class="attrib">@param</span> {String} name The root tag name of the packet
 * (i.e. one of 'message', 'iq' or 'presence')
 */</span>
<span class="reserved">function</span> JSJaCPacket(name) {
  <span class="comment">/**
   * <span class="attrib">@private</span>
   */</span>
  <span class="reserved">this</span>.name = name;

  <span class="reserved">if</span> (typeof(JSJACPACKET_USE_XMLNS) != <span class="literal">'undefined'</span> &amp;&amp; JSJACPACKET_USE_XMLNS)
    <span class="comment">/**
     * <span class="attrib">@private</span>
     */</span>
    <span class="reserved">this</span>.doc = XmlDocument.create(name,<span class="literal">'jabber:client'</span>);
  <span class="reserved">else</span>
    <span class="comment">/**
     * <span class="attrib">@private</span>
     */</span>
    <span class="reserved">this</span>.doc = XmlDocument.create(name,<span class="literal">''</span>);
}

<span class="comment">/**
 * Gets the type (name of root element) of this packet, i.e. one of
 * 'presence', 'message' or 'iq'
 * <span class="attrib">@return</span> the top level tag name
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.pType = <span class="reserved">function</span>() { <span class="reserved">return</span> <span class="reserved">this</span>.name; };

<span class="comment">/**
 * Gets the associated Document for this packet.
 * <span class="attrib">@type</span> {<span class="attrib">@link</span> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document Document}
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getDoc = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.doc;
};
<span class="comment">/**
 * Gets the root node of this packet
 * <span class="attrib">@type</span> {<span class="attrib">@link</span> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node}
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getNode = <span class="reserved">function</span>() {
  <span class="reserved">if</span> (<span class="reserved">this</span>.getDoc() &amp;&amp; <span class="reserved">this</span>.getDoc().documentElement)
    <span class="reserved">return</span> <span class="reserved">this</span>.getDoc().documentElement;
  <span class="reserved">else</span>
    <span class="reserved">return</span> null;
};

<span class="comment">/**
 * Sets the 'to' attribute of the root node of this packet
 * <span class="attrib">@param</span> {String} to
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.setTo = <span class="reserved">function</span>(to) {
  <span class="reserved">if</span> (!to || to == <span class="literal">''</span>)
    <span class="reserved">this</span>.getNode().removeAttribute(<span class="literal">'to'</span>);
  <span class="reserved">else</span> <span class="reserved">if</span> (typeof(to) == <span class="literal">'string'</span>)
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'to'</span>,to);
  <span class="reserved">else</span>
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'to'</span>,to.toString());
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the 'from' attribute of the root node of this
 * packet. Usually this is not needed as the server will take care
 * of this automatically.
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.setFrom = <span class="reserved">function</span>(from) {
  <span class="reserved">if</span> (!from || from == <span class="literal">''</span>)
    <span class="reserved">this</span>.getNode().removeAttribute(<span class="literal">'from'</span>);
  <span class="reserved">else</span> <span class="reserved">if</span> (typeof(from) == <span class="literal">'string'</span>)
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'from'</span>,from);
  <span class="reserved">else</span>
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'from'</span>,from.toString());
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets 'id' attribute of the root node of this packet.
 * <span class="attrib">@param</span> {String} id The id of the packet.
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.setID = <span class="reserved">function</span>(id) {
  <span class="reserved">if</span> (!id || id == <span class="literal">''</span>)
    <span class="reserved">this</span>.getNode().removeAttribute(<span class="literal">'id'</span>);
  <span class="reserved">else</span>
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'id'</span>,id);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the 'type' attribute of the root node of this packet.
 * <span class="attrib">@param</span> {String} type The type of the packet.
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.setType = <span class="reserved">function</span>(type) {
  <span class="reserved">if</span> (!type || type == <span class="literal">''</span>)
    <span class="reserved">this</span>.getNode().removeAttribute(<span class="literal">'type'</span>);
  <span class="reserved">else</span>
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'type'</span>,type);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets 'xml:lang' for this packet
 * <span class="attrib">@param</span> {String} xmllang The xml:lang of the packet.
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.setXMLLang = <span class="reserved">function</span>(xmllang) {
  <span class="reserved">if</span> (!xmllang || xmllang == <span class="literal">''</span>)
    <span class="reserved">this</span>.getNode().removeAttribute(<span class="literal">'xml:lang'</span>);
  <span class="reserved">else</span>
    <span class="reserved">this</span>.getNode().setAttribute(<span class="literal">'xml:lang'</span>,xmllang);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};

<span class="comment">/**
 * Gets the 'to' attribute of this packet
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getTo = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(<span class="literal">'to'</span>);
};
<span class="comment">/**
 * Gets the 'from' attribute of this packet.
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getFrom = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(<span class="literal">'from'</span>);
};
<span class="comment">/**
 * Gets the 'to' attribute of this packet as a JSJaCJID object
 * <span class="attrib">@type</span> JSJaCJID
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getToJID = <span class="reserved">function</span>() {
  <span class="reserved">return</span> new JSJaCJID(<span class="reserved">this</span>.getTo());
};
<span class="comment">/**
 * Gets the 'from' attribute of this packet as a JSJaCJID object
 * <span class="attrib">@type</span> JSJaCJID
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getFromJID = <span class="reserved">function</span>() {
  <span class="reserved">return</span> new JSJaCJID(<span class="reserved">this</span>.getFrom());
};
<span class="comment">/**
 * Gets the 'id' of this packet
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getID = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(<span class="literal">'id'</span>);
};
<span class="comment">/**
 * Gets the 'type' of this packet
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getType = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(<span class="literal">'type'</span>);
};
<span class="comment">/**
 * Gets the 'xml:lang' of this packet
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getXMLLang = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(<span class="literal">'xml:lang'</span>);
};
<span class="comment">/**
 * Gets the 'xmlns' (xml namespace) of the root node of this packet
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getXMLNS = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().namespaceURI;
};

<span class="comment">/**
 * Gets a child element of this packet. If no params given returns first child.
 * <span class="attrib">@param</span> {String} name Tagname of child to retrieve. Use '*' to match any tag. [optional]
 * <span class="attrib">@param</span> {String} ns   Namespace of child. Use '*' to match any ns.[optional]
 * <span class="attrib">@return</span> The child node, null if none found
 * <span class="attrib">@type</span> {<span class="attrib">@link</span> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node}
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getChild = <span class="reserved">function</span>(name, ns) {
  <span class="reserved">if</span> (!<span class="reserved">this</span>.getNode()) {
    <span class="reserved">return</span> null;
  }
 
  name = name || <span class="literal">'*'</span>;
  ns = ns || <span class="literal">'*'</span>;

  <span class="reserved">if</span> (<span class="reserved">this</span>.getNode().getElementsByTagNameNS) {
    <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getElementsByTagNameNS(ns, name).item(0);
  }

  <span class="comment">// fallback</span>
  var nodes = <span class="reserved">this</span>.getNode().getElementsByTagName(name);
  <span class="reserved">if</span> (ns != <span class="literal">'*'</span>) {
    <span class="reserved">for</span> (var i=0; i&lt;nodes.length; i++) {
      <span class="reserved">if</span> (nodes.item(i).namespaceURI == ns) {
        <span class="reserved">return</span> nodes.item(i);
      }
    }
  } <span class="reserved">else</span> {
    <span class="reserved">return</span> nodes.item(0);
  }
  <span class="reserved">return</span> null; <span class="comment">// nothing found</span>
}

<span class="comment">/**
 * Gets the node value of a child element of this packet.
 * <span class="attrib">@param</span> {String} name Tagname of child to retrieve.
 * <span class="attrib">@param</span> {String} ns   Namespace of child
 * <span class="attrib">@return</span> The value of the child node, empty string if none found
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.getChildVal = <span class="reserved">function</span>(name, ns) {
  var node = <span class="reserved">this</span>.getChild(name, ns);
  <span class="reserved">if</span> (node &amp;&amp; node.firstChild) {
    <span class="reserved">return</span> node.firstChild.nodeValue;
  } <span class="reserved">else</span> {
    <span class="reserved">return</span> <span class="literal">''</span>;
  }
};

<span class="comment">/**
 * Returns a copy of this node
 * <span class="attrib">@return</span> a copy of this node
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.clone = <span class="reserved">function</span>() {
  <span class="reserved">return</span> JSJaCPacket.wrapNode(<span class="reserved">this</span>.getNode());
};

<span class="comment">/**
 * Checks if packet is of type 'error'
 * <span class="attrib">@return</span> 'true' if this packet is of type 'error', 'false' otherwise
 * <span class="attrib">@type</span> boolean
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.isError = <span class="reserved">function</span>() {
  <span class="reserved">return</span> (<span class="reserved">this</span>.getType() == <span class="literal">'error'</span>);
};

<span class="comment">/**
 * Returns an error condition reply according to {<span class="attrib">@link</span> http://www.xmpp.org/extensions/xep-0086.html XEP-0086}. Creates a clone of the calling packet with senders and recipient exchanged and error stanza appended.
 * <span class="attrib">@param</span> {STANZA_ERROR} stanza_error an error stanza containing error cody, type and condition of the error to be indicated
 * <span class="attrib">@return</span> an error reply packet
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.errorReply = <span class="reserved">function</span>(stanza_error) {
  var rPacket = <span class="reserved">this</span>.clone();
  rPacket.setTo(<span class="reserved">this</span>.getFrom());
  rPacket.setFrom();
  rPacket.setType(<span class="literal">'error'</span>);

  rPacket.appendNode(<span class="literal">'error'</span>,
                     {code: stanza_error.code, type: stanza_error.type},
                     [[stanza_error.cond]]);

  <span class="reserved">return</span> rPacket;
};

<span class="comment">/**
 * Returns a string representation of the raw xml content of this packet.
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.xml = <span class="reserved">function</span>() {

  <span class="reserved">if</span> (<span class="reserved">this</span>.getDoc().xml) <span class="comment">// IE</span>
    <span class="reserved">return</span> <span class="reserved">this</span>.getDoc().xml;

  var xml = (new XMLSerializer()).serializeToString(<span class="reserved">this</span>.getNode());
  <span class="reserved">if</span> (typeof(xml) != <span class="literal">'undefined'</span>)
    <span class="reserved">return</span> xml;
  <span class="reserved">return</span> (new XMLSerializer()).serializeToString(<span class="reserved">this</span>.doc); <span class="comment">// oldschool</span>

};

<span class="comment">// PRIVATE METHODS DOWN HERE</span>

<span class="comment">/**
 * Gets an attribute of the root element
 * <span class="attrib">@private</span>
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>._getAttribute = <span class="reserved">function</span>(attr) {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getAttribute(attr);
};

<span class="comment">/**
 * Replaces this node with given node
 * <span class="attrib">@private</span>
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>._replaceNode = <span class="reserved">function</span>(aNode) {
  <span class="comment">// copy attribs</span>
  <span class="reserved">for</span> (var i=0; i&lt;aNode.attributes.length; i++)
    <span class="reserved">if</span> (aNode.attributes.item(i).nodeName != <span class="literal">'xmlns'</span>)
      <span class="reserved">this</span>.getNode().setAttribute(aNode.attributes.item(i).nodeName,
                                  aNode.attributes.item(i).nodeValue);

  <span class="comment">// copy children</span>
  <span class="reserved">for</span> (var i=0; i&lt;aNode.childNodes.length; i++)
    <span class="reserved">if</span> (<span class="reserved">this</span>.getDoc().importNode)
      <span class="reserved">this</span>.getNode().appendChild(<span class="reserved">this</span>.getDoc().importNode(aNode.
                                                          childNodes.item(i),
                                                          true));
    <span class="reserved">else</span>
      <span class="reserved">this</span>.getNode().appendChild(aNode.childNodes.item(i).cloneNode(true));
};
 
<span class="comment">/**
 * Set node value of a child node
 * <span class="attrib">@private</span>
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>._setChildNode = <span class="reserved">function</span>(nodeName, nodeValue) {
  var aNode = <span class="reserved">this</span>.getChild(nodeName);
  var tNode = <span class="reserved">this</span>.getDoc().createTextNode(nodeValue);
  <span class="reserved">if</span> (aNode)
    try {
      aNode.replaceChild(tNode,aNode.firstChild);
    } catch (e) { }
  <span class="reserved">else</span> {
    aNode = <span class="reserved">this</span>.getNode().appendChild(<span class="reserved">this</span>.getDoc().
                                       createElement(nodeName));
    aNode.appendChild(tNode);
  }
  <span class="reserved">return</span> aNode;
};

<span class="comment">/**
 * Builds a node using {<span class="attrib">@link</span>
 * http://wiki.script.aculo.us/scriptaculous/show/Builder
 * script.aculo.us' Dom Builder} notation.
 * This code is taken from {<span class="attrib">@link</span>
 * http://wiki.script.aculo.us/scriptaculous/show/Builder
 * script.aculo.us' Dom Builder} and has been modified to suit our
 * needs.&lt;br/&gt;
 * The original parts of the code do have the following copyright
 * and license notice:&lt;br/&gt;
 * Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us,
 * http://mir.acu lo.us) &lt;br/&gt;
 * script.aculo.us is freely distributable under the terms of an
 * MIT-style licen se.  // For details, see the script.aculo.us web
 * site: http://script.aculo.us/&lt;br&gt;
 * <span class="attrib">@author</span> Thomas Fuchs
 * <span class="attrib">@author</span> Stefan Strigler
 * <span class="attrib">@return</span> The newly created node
 * <span class="attrib">@type</span> {<span class="attrib">@link</span> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node}
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.buildNode = <span class="reserved">function</span>(elementName) {
  <span class="reserved">return</span> JSJaCBuilder.buildNode(<span class="reserved">this</span>.getDoc(),
                                elementName,
                                arguments[1],
                                arguments[2]);
};

<span class="comment">/**
 * Appends node created by buildNode to this packets parent node.
 * <span class="attrib">@param</span> {<span class="attrib">@link</span> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} element The node to append or
 * <span class="attrib">@param</span> {String} element A name plus an object hash with attributes (optional) plus an array of childnodes (optional)
 * <span class="attrib">@see</span> #buildNode
 * <span class="attrib">@return</span> This packet
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.<span class="reserved">prototype</span>.appendNode = <span class="reserved">function</span>(element) {
  <span class="reserved">if</span> (typeof element==<span class="literal">'object'</span>) { <span class="comment">// seems to be a prebuilt node</span>
    <span class="reserved">return</span> <span class="reserved">this</span>.getNode().appendChild(element)
  } <span class="reserved">else</span> { <span class="comment">// build node</span>
    <span class="reserved">return</span> <span class="reserved">this</span>.getNode().appendChild(<span class="reserved">this</span>.buildNode(element,
                                                     arguments[1],
                                                     arguments[2]));
  }
};


<span class="comment">/**
 * A jabber/XMPP presence packet
 * <span class="attrib">@class</span> Models the XMPP notion of a 'presence' packet
 * <span class="attrib">@extends</span> JSJaCPacket
 */</span>
<span class="reserved">function</span> JSJaCPresence() {
  <span class="comment">/**
   * <span class="attrib">@ignore</span>
   */</span>
  <span class="reserved">this</span>.base = JSJaCPacket;
  <span class="reserved">this</span>.base(<span class="literal">'presence'</span>);
}
JSJaCPresence.<span class="reserved">prototype</span> = new JSJaCPacket;

<span class="comment">/**
 * Sets the status message for current status. Usually this is set
 * to some human readable string indicating what the user is
 * doing/feel like currently.
 * <span class="attrib">@param</span> {String} status A status message
 * <span class="attrib">@return</span> this
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.setStatus = <span class="reserved">function</span>(status) {
  <span class="reserved">this</span>._setChildNode(<span class="literal">"status"</span>, status);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the online status for this presence packet.
 * <span class="attrib">@param</span> {String} show An XMPP complient status indicator. Must
 * be one of 'chat', 'away', 'xa', 'dnd'
 * <span class="attrib">@return</span> this
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.setShow = <span class="reserved">function</span>(show) {
  <span class="reserved">if</span> (show == <span class="literal">'chat'</span> || show == <span class="literal">'away'</span> || show == <span class="literal">'xa'</span> || show == <span class="literal">'dnd'</span>)
    <span class="reserved">this</span>._setChildNode(<span class="literal">"show"</span>,show);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the priority of the resource bind to with this connection
 * <span class="attrib">@param</span> {int} prio The priority to set this resource to
 * <span class="attrib">@return</span> this
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.setPriority = <span class="reserved">function</span>(prio) {
  <span class="reserved">this</span>._setChildNode(<span class="literal">"priority"</span>, prio);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Some combined method that allowes for setting show, status and
 * priority at once
 * <span class="attrib">@param</span> {String} show A status message
 * <span class="attrib">@param</span> {String} status A status indicator as defined by XMPP
 * <span class="attrib">@param</span> {int} prio A priority for this resource
 * <span class="attrib">@return</span> this
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.setPresence = <span class="reserved">function</span>(show,status,prio) {
  <span class="reserved">if</span> (show)
    <span class="reserved">this</span>.setShow(show);
  <span class="reserved">if</span> (status)
    <span class="reserved">this</span>.setStatus(status);
  <span class="reserved">if</span> (prio)
    <span class="reserved">this</span>.setPriority(prio);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};

<span class="comment">/**
 * Gets the status message of this presence
 * <span class="attrib">@return</span> The (human readable) status message
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.getStatus = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'status'</span>);
};
<span class="comment">/**
 * Gets the status of this presence.
 * Either one of 'chat', 'away', 'xa' or 'dnd' or null.
 * <span class="attrib">@return</span> The status indicator as defined by XMPP
 * <span class="attrib">@type</span> String
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.getShow = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'show'</span>);
};
<span class="comment">/**
 * Gets the priority of this status message
 * <span class="attrib">@return</span> A resource priority
 * <span class="attrib">@type</span> int
 */</span>
JSJaCPresence.<span class="reserved">prototype</span>.getPriority = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'priority'</span>);
};


<span class="comment">/**
 * A jabber/XMPP iq packet
 * <span class="attrib">@class</span> Models the XMPP notion of an 'iq' packet
 * <span class="attrib">@extends</span> JSJaCPacket
 */</span>
<span class="reserved">function</span> JSJaCIQ() {
  <span class="comment">/**
   * <span class="attrib">@ignore</span>
   */</span>
  <span class="reserved">this</span>.base = JSJaCPacket;
  <span class="reserved">this</span>.base(<span class="literal">'iq'</span>);
}
JSJaCIQ.<span class="reserved">prototype</span> = new JSJaCPacket;

<span class="comment">/**
 * Some combined method to set 'to', 'type' and 'id' at once
 * <span class="attrib">@param</span> {String} to the recepients JID
 * <span class="attrib">@param</span> {String} type A XMPP compliant iq type (one of 'set', 'get', 'result' and 'error'
 * <span class="attrib">@param</span> {String} id A packet ID
 * <span class="attrib">@return</span> this
 * <span class="attrib">@type</span> JSJaCIQ
 */</span>
JSJaCIQ.<span class="reserved">prototype</span>.setIQ = <span class="reserved">function</span>(to,type,id) {
  <span class="reserved">if</span> (to)
    <span class="reserved">this</span>.setTo(to);
  <span class="reserved">if</span> (type)
    <span class="reserved">this</span>.setType(type);
  <span class="reserved">if</span> (id)
    <span class="reserved">this</span>.setID(id);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Creates a 'query' child node with given XMLNS
 * <span class="attrib">@param</span> {String} xmlns The namespace for the 'query' node
 * <span class="attrib">@return</span> The query node
 * <span class="attrib">@type</span> {<span class="attrib">@link</span>  http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node}
 */</span>
JSJaCIQ.<span class="reserved">prototype</span>.setQuery = <span class="reserved">function</span>(xmlns) {
  var query;
  try {
    query = <span class="reserved">this</span>.getDoc().createElementNS(xmlns,<span class="literal">'query'</span>);
  } catch (e) {
    <span class="comment">// fallback</span>
    query = <span class="reserved">this</span>.getDoc().createElement(<span class="literal">'query'</span>);
  }
  <span class="reserved">if</span> (query &amp;&amp; query.getAttribute(<span class="literal">'xmlns'</span>) != xmlns) <span class="comment">// fix opera 8.5x</span>
    query.setAttribute(<span class="literal">'xmlns'</span>,xmlns);
  <span class="reserved">this</span>.getNode().appendChild(query);
  <span class="reserved">return</span> query;
};

<span class="comment">/**
 * Gets the 'query' node of this packet
 * <span class="attrib">@return</span> The query node
 * <span class="attrib">@type</span> {<span class="attrib">@link</span>  http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node}
 */</span>
JSJaCIQ.<span class="reserved">prototype</span>.getQuery = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getNode().getElementsByTagName(<span class="literal">'query'</span>).item(0);
};
<span class="comment">/**
 * Gets the XMLNS of the query node contained within this packet
 * <span class="attrib">@return</span> The namespace of the query node
 * <span class="attrib">@type</span> String
 */</span>
JSJaCIQ.<span class="reserved">prototype</span>.getQueryXMLNS = <span class="reserved">function</span>() {
  <span class="reserved">if</span> (<span class="reserved">this</span>.getQuery())
    <span class="reserved">return</span> <span class="reserved">this</span>.getQuery().namespaceURI;
  <span class="reserved">else</span>
    <span class="reserved">return</span> null;
};

<span class="comment">/**
 * Creates an IQ reply with type set to 'result'. If given appends payload to first child if IQ. Payload maybe XML as string or a DOM element (or an array of such elements as well).
 * <span class="attrib">@param</span> {Element} payload A payload to be appended [optional]
 * <span class="attrib">@return</span> An IQ reply packet
 * <span class="attrib">@type</span> JSJaCIQ
 */</span>
JSJaCIQ.<span class="reserved">prototype</span>.reply = <span class="reserved">function</span>(payload) {
  var rIQ = <span class="reserved">this</span>.clone();
  rIQ.setTo(<span class="reserved">this</span>.getFrom());
  rIQ.setType(<span class="literal">'result'</span>);
  <span class="reserved">if</span> (payload) {
    <span class="reserved">if</span> (typeof payload == <span class="literal">'string'</span>)
      rIQ.getChild.appendChild(rIQ.getDoc().loadXML(payload));
    <span class="reserved">else</span> <span class="reserved">if</span> (payload.constructor == Array) {
      var node = rIQ.getChild();
      <span class="reserved">for</span> (var i=0; i&lt;payload.length; i++)
        <span class="reserved">if</span>(typeof payload[i] == <span class="literal">'string'</span>)
          node.appendChild(rIQ.getDoc().loadXML(payload[i]));
        <span class="reserved">else</span> <span class="reserved">if</span> (typeof payload[i] == <span class="literal">'object'</span>)
          node.appendChild(payload[i]);
    }
    <span class="reserved">else</span> <span class="reserved">if</span> (typeof payload == <span class="literal">'object'</span>)
      rIQ.getChild().appendChild(payload);
  }
  <span class="reserved">return</span> rIQ;
};

<span class="comment">/**
 * A jabber/XMPP message packet
 * <span class="attrib">@class</span> Models the XMPP notion of an 'message' packet
 * <span class="attrib">@extends</span> JSJaCPacket
 */</span>
<span class="reserved">function</span> JSJaCMessage() {
  <span class="comment">/**
   * <span class="attrib">@ignore</span>
   */</span>
  <span class="reserved">this</span>.base = JSJaCPacket;
  <span class="reserved">this</span>.base(<span class="literal">'message'</span>);
}
JSJaCMessage.<span class="reserved">prototype</span> = new JSJaCPacket;

<span class="comment">/**
 * Sets the body of the message
 * <span class="attrib">@param</span> {String} body Your message to be sent along
 * <span class="attrib">@return</span> this message
 * <span class="attrib">@type</span> JSJaCMessage
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.setBody = <span class="reserved">function</span>(body) {
  <span class="reserved">this</span>._setChildNode(<span class="literal">"body"</span>,body);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the subject of the message
 * <span class="attrib">@param</span> {String} subject Your subject to be sent along
 * <span class="attrib">@return</span> this message
 * <span class="attrib">@type</span> JSJaCMessage
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.setSubject = <span class="reserved">function</span>(subject) {
  <span class="reserved">this</span>._setChildNode(<span class="literal">"subject"</span>,subject);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Sets the 'tread' attribute for this message. This is used to identify
 * threads in chat conversations
 * <span class="attrib">@param</span> {String} thread Usually a somewhat random hash.
 * <span class="attrib">@return</span> this message
 * <span class="attrib">@type</span> JSJaCMessage
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.setThread = <span class="reserved">function</span>(thread) {
  <span class="reserved">this</span>._setChildNode(<span class="literal">"thread"</span>, thread);
  <span class="reserved">return</span> <span class="reserved">this</span>;
};
<span class="comment">/**
 * Gets the 'thread' identifier for this message
 * <span class="attrib">@return</span> A thread identifier
 * <span class="attrib">@type</span> String
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.getThread = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'thread'</span>);
};
<span class="comment">/**
 * Gets the body of this message
 * <span class="attrib">@return</span> The body of this message
 * <span class="attrib">@type</span> String
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.getBody = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'body'</span>);
};
<span class="comment">/**
 * Gets the subject of this message
 * <span class="attrib">@return</span> The subject of this message
 * <span class="attrib">@type</span> String
 */</span>
JSJaCMessage.<span class="reserved">prototype</span>.getSubject = <span class="reserved">function</span>() {
  <span class="reserved">return</span> <span class="reserved">this</span>.getChildVal(<span class="literal">'subject'</span>)
};


<span class="comment">/**
 * Tries to transform a w3c DOM node to JSJaC's internal representation
 * (JSJaCPacket type, one of JSJaCPresence, JSJaCMessage, JSJaCIQ)
 * <span class="attrib">@param</span>: {Node
 * http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247}
 * node The node to be transformed
 * <span class="attrib">@return</span> A JSJaCPacket representing the given node. If node's root
 * elemenent is not one of 'message', 'presence' or 'iq',
 * &lt;code&gt;null&lt;/code&gt; is being returned.
 * <span class="attrib">@type</span> JSJaCPacket
 */</span>
JSJaCPacket.wrapNode = <span class="reserved">function</span>(node) {
  var aNode;
  switch (node.nodeName.toLowerCase()) {
  case <span class="literal">'presence'</span>:
    aNode = new JSJaCPresence();
    break;
  case <span class="literal">'message'</span>:
    aNode = new JSJaCMessage();
    break;
  case <span class="literal">'iq'</span>:
    aNode = new JSJaCIQ();
    break;
  default : <span class="comment">// unknown</span>
    <span class="reserved">return</span> null;
  }

  aNode._replaceNode(node);

  <span class="reserved">return</span> aNode;
};

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JSJaC</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Feb 12 18:46:55 2008</div>
</body>
</html>
